package com.menfan.saas.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.menfan.saas.common.ResultObject;
import com.menfan.saas.model.User;
import com.menfan.saas.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2018/6/30 0030.
 */
@RestController
@Slf4j
public class UserApi {
    @Autowired
    private IUserService iUserService;

    @RequestMapping("/user/{id}")
    public ResultObject getUserInfo(@PathVariable Integer id) {
        log.info("请求数据：{}" + id);
        return new ResultObject(iUserService.getUserInfo(id));
    }

    @RequestMapping("/user/list")
    public ResultObject getUserInfoList( int pageNum,int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> userList = iUserService.getUserList();
        PageInfo<User> pageInfo = new PageInfo<User>(userList);
        return new ResultObject(pageInfo);
    }
    @RequestMapping("/adduser")
    public ResultObject addUserInfo(String name) {
        iUserService.addUserInfo(name);
        return new ResultObject();
    }
}
